package com.xiaochen.manager.controller;

import com.github.pagehelper.PageInfo;
import com.xiaochen.manager.service.ProductSpecService;
import com.xiaochen.model.entity.product.ProductSpec;
import com.xiaochen.model.vo.common.Result;
import com.xiaochen.model.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品规格
 * @author pinkhors
 */
@RestController
@RequestMapping("/admin/product/productSpec")
public class ProductSpecController {

    @Autowired
    private ProductSpecService productSpecService;

    /**
     * 分页条件查询
     */
    @GetMapping("/selectByPage/{pageNum}/{pageSize}")
    public Result selectByPage(ProductSpec productSpec,
                               @PathVariable Integer pageNum,
                               @PathVariable Integer pageSize){
        PageInfo<ProductSpec> list = productSpecService.selectByPage(productSpec,pageNum,pageSize);
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    /**
     * 添加
     */
    @PostMapping("/saveProductSpec")
    public Result saveProductSpec(@RequestBody ProductSpec productSpec){
        productSpecService.saveProductSpec(productSpec);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 删除
     */
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Long id){
        productSpecService.deleteById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }


    /**
     * 修改
     */
    @PutMapping("/updateProductSpec")
    public Result updateProductSpec(@RequestBody ProductSpec productSpec){
        productSpecService.updateProductSpec(productSpec);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 查询出来所有的商品规格数据
     */
    @GetMapping("findAll")
    public Result findAll() {
        List<ProductSpec> list = productSpecService.findAll();
        return Result.build(list , ResultCodeEnum.SUCCESS) ;
    }
}
